import java.util.Arrays;
import java.util.Stack;

public class _155最小栈 {
    static class MinStack {
        private Stack<Integer> stack=new Stack<>();
        private Stack<Integer> minStack=new Stack<>();

        public void push(int val) {
            stack.push(val);
            if(minStack.isEmpty()||val<=minStack.peek()){
                minStack.push(val);
            }
        }
        
        public void pop() {
            Integer pop = stack.pop();
            if(pop.equals(minStack.peek())){
                minStack.pop();
            }
        }
        
        public int top() {
            return stack.peek();
        }
        
        public int getMin() {
            return minStack.peek();
        }
       
       
    }

    public static void main(String[] args) {
        MinStack minStack = new MinStack();
        minStack.push(1);
        minStack.push(-2);
        minStack.push(0);
        int min = minStack.getMin();
        System.out.println(min);
        minStack.pop();
        int min2 = minStack.getMin();
        System.out.println(min2);
    }
}
